﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using PumeCentralService;
namespace DummyClient
{
    [CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)]
    class DummyClient : IPumpCentralCallback , IDisposable
    {
        IPumpCentalService Central = null;

        public PumpStatusDTO getWaterLevel()
        {
            return new PumpStatusDTO() { ID = "id",waterLevel = 10.0, status = Status.active}; 
        }

        public bool StartPump()
        {
            Console.WriteLine("Starter pumpe");
            return true;
        }

        public bool StopPump()
        {
            return true;
        }

        public void Dispose()
        {
            throw new NotImplementedException();
        }

        public bool Connect()
        {           
            try
            {
                DuplexChannelFactory<IPumpCentalService> CentralChannel = new DuplexChannelFactory<IPumpCentalService>(new InstanceContext(this), new NetTcpBinding(), new EndpointAddress(PumpCentralServiceKonstants.URI));
                Central = CentralChannel.CreateChannel();
                bool success = Central.SubscribeFromPump(new PumpStatusDTO { ID = "id", waterLevel = 10.0, status = Status.active });
                if (success)
                { 
                    Console.WriteLine("Jubii"); 
                }
                return true;
            }
            catch(CommunicationException ce)
            {
                return false;
            }
        }


       public bool RegisterPump(PumpStatusDTO dto)
        {
            return false;
        }     
        
       public bool UnregisterPump(PumpStatusDTO dto)
       {
           return false;
       }

       double IPumpCentralCallback.getWaterLevel()
       {
           throw new NotImplementedException();
       }

       public PumpStatusDTO GetData()
       {
           throw new NotImplementedException();
       }
    }
}
